﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Forms.Design.Behavior;
using System.Drawing;
using System.Windows.Forms;
using SharedClasses;

namespace UIDesigner.DesignContainers.Glyphs
{
    public class OverlayGlyph : Glyph
    {
        private Control control;
        private BehaviorService behaviorSvc;
        private Glyph m_objGlyphOverLaid;

        public OverlayGlyph(BehaviorService behaviorSvc, Control control, Glyph objGlyphOverLaid) : base(new OverlayBehavior())
        {
            this.behaviorSvc = behaviorSvc;
            this.control = control;

            m_objGlyphOverLaid = objGlyphOverLaid;
        }

        public override Rectangle Bounds
        {
            get
            {
                Rectangle rc = m_objGlyphOverLaid.Bounds;

                rc.Inflate(2, 2);
                return rc;
            }
        }

        public override Cursor GetHitTest(Point p)
        {
            // GetHitTest is called to see if the point is
            // within this glyph.  This gives us a chance to decide
            // what cursor to show.  Returning null from here means
            // the mouse pointer is not currently inside of the glyph.
            // Returning a valid cursor here indicates the pointer is
            // inside the glyph, and also enables our Behavior property
            // as the active behavior.
            if (Bounds.Contains(p))
            {
                return Cursors.Default;
            }

            return null;
        }

        public override void Paint(PaintEventArgs pe)
        {
            //e.Graphics.FillRectangle(Brushes.Blue, Bounds);
        }

        // By providing our own behavior we can do something interesting
        // when the user clicks or manipulates our glyph.
        public class OverlayBehavior : Behavior
        {
            public override bool OnMouseDown(Glyph g, MouseButtons button, Point mouseLoc)
            {
                return true;
            }

            public override bool OnMouseUp(Glyph g, MouseButtons button)
            {
                return true; // indicating we processed this event.
            }
        }
    }
}
